package com.hxc.exception;

import com.hxc.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 设置全局异常处理器，统一处理异常
 * */
@Slf4j
@RestControllerAdvice //用来捕获Controller层异常
// 包括@ResponseBod\ @ControllerAdvice
public class GlobalExceptionalHandler {
    @ExceptionHandler(value = Exception.class) //value = Exception.class处理全部异常，默认值
    public Result doException(Exception e) {
        //log.error(e.getMessage());
        log.error("异常:",e);
        return Result.error("出错了，请联系管理员");
    }
}
